--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

DROP TABLE se_gam_outil;

CREATE TABLE se_gam_outil AS (SELECT * FROM &erp.gam_outil WHERE 1=2);




 INSERT INTO se_gam_outil

    (SELECT id outil_cod,
            NULL untps_cod,
            NULL uo_cod,
            0 enreg_id,
            'N' enreg_s,
            des outil_lib,
            NULL outil_lib2,
            NULL perio_outil_val

        FROM uv_poutils
        ) ;

 UPDATE se_gam_outil tf SET enreg_id=(select enreg_id FROM &erp.gam_outil f WHERE f.outil_cod=tf.outil_cod) ;
 UPDATE se_gam_outil tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('outil_cod','GAM_OUTIL','O') ;

 commit;
 
 
select * from (
SELECT &outils.stragg(source) source,outil_cod, untps_cod, uo_cod, enreg_id, enreg_s, outil_lib, outil_lib2, perio_outil_val
FROM (
  SELECT 'uv' source ,g.* FROM se_gam_outil g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.gam_outil g

  )
GROUP BY outil_cod, untps_cod, uo_cod, enreg_id, enreg_s, outil_lib, outil_lib2, perio_outil_val
HAVING Count(1)!=2) r
ORDER BY  outil_cod ;